import { createI18n } from "vue-i18n";
import zh from "./zh";
import en from "./en";

const messages = {
    zh: {
        ...zh
    },
    en: {
        ...en
    }
}

function getLocal() {
    const myLocal = localStorage.getItem('language')//获取当前存储的语言

    // 如果缓存中存在直接返回
    if (myLocal) {
        return myLocal
    }
    // 读取当前网页语言
    const localeName = navigator.language.indexOf('en') !== -1 ? 'zh' : 'en'
    // 将当前网页语言存储起来
    localStorage.setItem('language', localeName)
}

export const i18n = createI18n({
    locale: getLocal(),
    messages
})